import os
import shutil

from tqdm import tqdm

def checkDirForDeepIsExists(dir_name):
    if not os.path.exists(dir_name):  # os模块判断并创建
        deep_dir_name = os.path.dirname(dir_name)
        checkDirForDeepIsExists(deep_dir_name)
        os.mkdir(dir_name)

deepLearningDataPath="G:\数据集\植保所\分类目标图片\外来入侵害虫\深度学习数据集\imagenet230327"
resultPath="G:\数据集\植保所\分类目标图片\外来入侵害虫\重新整理后纯英的数据集"

modes=os.listdir(deepLearningDataPath)

for mode in modes:
    classes=os.listdir(os.path.join(deepLearningDataPath,mode))

    for imgClass in tqdm(classes):
        checkDirForDeepIsExists(os.path.join(resultPath, imgClass))
        imgs = os.listdir(os.path.join(deepLearningDataPath, mode,imgClass))
        for img in imgs:
            shutil.copy(os.path.join(deepLearningDataPath,mode,imgClass,img),os.path.join(resultPath,imgClass,img))
